// EverbirdArmrClientDlg.h : header file
//

#pragma once
#include "WinSocket2Communicator.h"
#include "PUDData.h"
#include "afxwin.h"

// CEverbirdArmrClientDlg dialog
class CEverbirdArmrClientDlg : public CDialog
{
// Construction
public:
	CEverbirdArmrClientDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_EVERBIRDARMRCLIENT_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
public:
	DWORD SLEEP_REGULAR_SENDDATA;
	DWORD SLEEP_CONNECT_CLIENT_RETRY;
	DWORD SLEEP_WARNING_RETRY;
	DWORD SLEEP_OVERLOAD_RETRY;
	DWORD SLEEP_HEARTBEAT;
	DWORD SLEEP_HEARTBEAT_RETRY;
	int clientListenerPort;
	int clientSpeakerPort;
	int centerListenerPort;
	int centerSpeakerPort;
	bool isListenerStarted;
	bool receivedWarningACK;
	CString IPbyId[256];
	int	warningListForFC[5];
	int currentWarning;
	int RPID;
	WinSocket2Communicator* m_comm;
	PUDData _pudData;
	char szBinaryFrame[BINARY_FRAME_SIZE];
	char szFrameString[MAX_DATA_LENGTH];
	ParseUtil _parseUtil;
	bool isRegularSendStarted;
protected:
	HICON m_hIcon;
	HANDLE m_commListenThread;
	HANDLE m_commSpeakThread;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	void updateDataToBinaryFrame();
	void createSpeakThread(DWORD threadId);
	void createListenThread();
	void dealWithFunctionCode();
	void dealWithReceivedFrame();
	void sendDataToCenter();
	void initData();
	void setBinaryFrame(char* szBinaryFrame);
	void setFrameString(char* szFrameString);
	void regularSendDataRetryWarning();
	void sendHeartbeatACK();

	void clearErrorWarning();
	void notReceiveWarningACKWarning(int retryTime);

	void initIPbyId();
	void loadAllIPFromConfig();
	void loadSleepTimeFromConfig();
	void setupSelectedClientById(int Id);
public:
	afx_msg void OnBnClickedStartListenerBtn();
public:
	CEdit m_ctrlAV;
public:
	CEdit m_ctrlBV;
public:
	CEdit m_ctrlCV;
public:
	CEdit m_ctrlAA;
public:
	CEdit m_ctrlBA;
public:
	CEdit m_ctrlCA;
public:
	CEdit m_ctrlAW;
public:
	CEdit m_ctrlBW;
public:
	CEdit m_ctrlCW;
public:
	CEdit m_ctrlSelfAddress;
public:
	CEdit m_ctrlSendFrame;
public:
	CEdit m_ctrlReceiveFrame;
public:
	afx_msg void OnBnClickedSpeakerTest();
public:
	afx_msg void OnBnClickedRegularSendBtn();
public:
	CEdit m_ctrlWarningMsg;
public:
	CEdit m_ctrlErrStatus;
public:
	CEdit m_ctrlLastSendTime;
public:
	CEdit m_ctrlLastReceiveTime;
public:
	CButton m_ctrlRegularSendBtn;
public:
	CComboBox m_ctrlSelfId;
public:
	afx_msg void OnCbnSelchangeSelfId();
public:
	CComboBox m_ctrlWarningList;
public:
	afx_msg void OnBnClickedSendWarning();
public:
	afx_msg void OnCbnSelchangeWarningList();
public:
	CEdit m_ctrlDesAddress;
public:
	CButton m_ctrlStartListener;
};
DWORD ListenerThread(CEverbirdArmrClientDlg* lpparam);
DWORD SpeakerThreadWarning(CEverbirdArmrClientDlg* lpparam);
